<template>
  <div class="radio">
    <scroll :list="rankRadioList" :top="139" :bottom="80" ref="rscroll">
      <div>
        <radio-swiper :swiperOptions="swiperOptions" :swiperList="radioSwiperList" @img-ready="scrollRefresh"></radio-swiper>
        <radio-list :hotRadioList="hotRadioList" :newRadioList="newRadioList" :rankRadioList="rankRadioList" @get-radio-song="getRadioSong"
         @to-radio-detail="toRadioDetail"></radio-list>
      </div>
    </scroll>
  </div>
</template>

<script>
  import RadioList from '@/components/main/radio/RadioList'
  import Scroll from '@/components/scroll'
  import RadioSwiper from '@/components/main/radio/RadioSwiper'
  export default {
    data() {
      return {
        //轮播图配置
        swiperOptions: {
        	pagination: {
        		el: '.swiper-pagination'
        	},
        	loop: true,
        	autoplay: true
        },
        //轮播图数据
        radioSwiperList: [],
        //热门电台数据
        hotRadioList:[],
        //新晋电台数据
        newRadioList:[],
        //榜单电台数据
        rankRadioList:[]
      }
    },
    created() {
      this.getSwiperList()
      this.getHotRadioList()
      this.getNewRadioList()
      this.getRankRadioList()
    },
    methods: {
      //获取轮播图数据
      async getSwiperList() {
        const res = await this.$http.get('/dj/banner');
        this.radioSwiperList = res.data.data.map(item => ({
        	img: item.pic
        }))
      },
      //获取热门电台数据
      async getHotRadioList() {
        const { data: res } = await this.$http.get('/dj/toplist?type=hot&limit=3')
        this.hotRadioList = res.toplist
      },
      //获取新晋电台数据
      async getNewRadioList() {
        const { data: res } = await this.$http.get('/dj/toplist?type=new&limit=3')
        this.newRadioList = res.toplist
      },
      //获取榜单电台数据
      async getRankRadioList() {
        const { data: res } = await this.$http.get('/dj/program/toplist/hours?limit=3')
        this.rankRadioList = res.data.list
      },
      scrollRefresh() {
        this.$refs.rscroll.refresh()
      },
      //获取电台歌曲
      async getRadioSong(id) {
        const { data: res } = await this.$http.get('/song/url?id=' + id)
        this.$parent.url = res.data[0].url
      },
      toRadioDetail(id,name){
        this.$router.push({path:'/radiodetail',query: {id,name}})
      }
    },
    components: {
      RadioList,
      Scroll,
      RadioSwiper
    }
  }
</script>

<style>
</style>
